import {BeatMapParser, NoteEvent, WallEvent} from "./BeatMapParser"
class BeatMapParserV2 extends BeatMapParser{
  constructor(info, data){
    super(info, data)
  }

  initNoteEvents(){
    for(let i= 0; i < this.data['_notes'].length; i++){
      const rawData = this.data['_notes'][i]
      const newEvent = new NoteEvent()
      Object.assign(newEvent, {
        Index: i,
        Beat: rawData._time,
        LineIndex: rawData._lineIndex,
        LineLayer: rawData._lineLayer,
        Type: rawData._type,
        CutDirection: rawData._cutDirection
      })
      this.noteEvents.push(newEvent)
    }
  }

  initWallEvents(){
    for(let i= 0; i < this.data['_obstacles'].length; i++){
      const rawData = this.data['_obstacles'][i]
      let type = rawData['_type'];
      let wallY = type == 0 ? 0:2;
      let wallH = type == 0 ? 5:3;
      if(type >= 1000) {
        if(type > 4000){
          type = type - 4001;
          const position = type %1000;
          const height = (type-position)/1000;

          wallY = position * 5 + 1000;
          wallH = height * 5 + 1000;
        } else {
          const height = type - 1000;
          wallH = height * 5 + 1000;
          wallY = 0;
        }
      }

      const newEvent = new WallEvent()
      Object.assign(newEvent, {
        Index: i,
        Beat: rawData._time,
        LineIndex: rawData._lineIndex,
        LineLayer: wallY,
        Height: wallH,
        Width: rawData._width,
        Duration: rawData._duration
      })
      this.wallEvents.push(newEvent)
    }
  }
}

export {BeatMapParserV2}